home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / glassme / gme03 < prev    next >
Text File  |  1991-02-19  |  4KB  |  109 lines

  1.  
  2.  
  3. umin (>"_"+x,x>):->;
  4. umin (>"-"+x,x>):->;
  5. umin (>x,"_"+x>):.
  6.  
  7. int of float (>INT+y,INT>):.
  8.  
  9. INT ::@ i num (x>).
  10.  
  11. i num (x>): !0123456789! +(x>), ->;
  12. i num ("0">): ^!! * (x>). 
  13.  
  14. TRUE  :: "True".
  15. FALSE :: "False".
  16.  
  17. condition (>TRUE,>then part,>else part, then part>): ->;
  18. condition (>FALSE,>then part,>else part, else part>):->;
  19. condition (>x,>then part,>else part, VErr*STRING*"*** Bool required ">):.
  20.  
  21. %TEX     
  22. \subsubsection{Transform indices VBuiltin {\tt "[]"}}
  23. %
  24. index (>"-"+x,>y,VErr*STRING*msg>): ->, 
  25.    where (>"*** Negative index : -"+x, msg>);
  26. index (>"_"+x,>y,VErr*STRING*msg>): ->, 
  27.    where (>"*** Negative index : -"+x, msg>);
  28. index (>nr,>VList*LIST*args, list index>): ->,
  29.    list index (>nr,>args, list index>);
  30. index (>nr,>cons, cons index>):
  31.    where (>cons,VComp*_>), ->,
  32.    cons index (>nr,>cons, cons index>);
  33. index (>nr,>cons, VInd*cons*I NUM *nr>):.
  34.    
  35.  
  36. list index (>nr,>VList*LIST*empty, VErr*STRING*msg>): ->, 
  37.    where (>"*** Index out of range:", msg>);
  38. list index (>"0",>a*r, a>): ->; 
  39. list index (>MINUS 1,>a*r, x>): 
  40.   list index(>MINUS 1,>r,x>), ->;
  41. list index (>nr,>el,VInd*el*I NUM *nr>):. 
  42.  
  43. cons index (>nr,>VList*LIST*empty, VErr*STRING*msg>): 
  44.    where (>"*** Index out of range ", msg>), ->;
  45. cons index (>"0",>VComp*a*r, a>): ->;
  46. cons index (>MINUS 1,>VComp*a*r, x>): ->,
  47.   cons index (>MINUS 1,>r,x>);
  48. cons index (>nr,>el,VInd*el*I NUM *nr>):.
  49.  
  50.  
  51. slice (>lw,>upb,>VList*LIST* els ,slice>): ->,
  52.   skip lwb list elements (>lw, >els,>els, n els>, rest lw>),
  53.   more list slice  (>rest lw,>lw, >upb, >n els, slice>);
  54. slice (>lw,>upb,>cons, slice>):
  55.    where (>cons,VComp*_>), ->,
  56.    skip lwb cons elements (>lw, >cons, ncons>, rest lw>),
  57.   more cons slice  (>rest lw,>lw, >upb, >n cons, slice>);
  58. slice (>lw,>upb,>nocons, VSlice*no cons*lw'*upb'>):
  59.    where (>I NUM*lw, lw'>),
  60.    where (>I NUM*upb, upb'>).
  61.  
  62. more list slice (>"0",>lw, >upb,>n els, slice>): ->,
  63.     compute (>upb + "-"+lw+"+1", nr>),
  64.     list slice (> nr, >n els, slice>);
  65. more list slice (>rest,>lw, >upb,>r, slice>):
  66.     compute (>upb + "-"+lw+"+"+rest, nu>),
  67.     where (>VSlice*r*l*u,slice>),
  68.     where (>I NUM*rest, l>),
  69.     where (>I NUM*nu, u>).
  70.  
  71. more cons slice (>"0",>lw, >upb,>n els, slice>): ->,
  72.     compute (>upb + "-"+lw+"+1", nr>),
  73.     cons slice (> nr, >n els, slice>);
  74. more cons slice (>rest,>lw, >upb,>r, slice>):
  75.     compute (>upb + "-"+lw+"+"+rest, nu>),
  76.     where (>VSlice*r*l*u,slice>),
  77.     where (>I NUM*rest, l>),
  78.     where (>I NUM*nu, u>).
  79.  
  80. list slice (>"-"+x, >els , empty>): ->;
  81. list slice (>"0", >els , empty>): ->;
  82. list slice (>MINUS 1, >e*ee , VComp*e*slice>): 
  83.    list slice (>MINUS 1, >ee, slice>), ->;
  84. list slice (>MINUS 1,>r, slice >): 
  85.     where (>VSlice*r*zero*upb,slice>),
  86.     where (>I NUM*"0", zero>),
  87.     where (>I NUM*MINUS 1, upb>).
  88.     
  89.      
  90. skip lwb list elements (>"0", >prev,>els, els>, "0">): ->;
  91. skip lwb list elements (>MINUS 1, >prev,>cur , n els>, rest>):
  92.      where (>cur, el*r>),
  93.      skip lwb list elements (>MINUS 1,>prev,>r, n els>, rest>), ->;
  94. skip lwb list elements (>rest , >prev, >empty , prev>, rest>):.
  95.  
  96. skip lwb cons elements (>"0",>els, els>, "0">): ->;
  97. skip lwb cons elements (>MINUS 1,>VComp*a*r, x>, rest>):  ->,
  98.   skip lwb cons elements (>MINUS 1,>r,x>, rest>);
  99. skip lwb cons elements (>rest,>last el, last el>,rest>):. 
  100.  
  101. cons slice (>"-"+x, >els ,  VList*LIST*empty>): ->;
  102. cons slice (>"0",>els, VList*LIST*empty>): ->;
  103. cons slice (>MINUS 1,>VComp*a*r,  VComp*a*slice>): 
  104.   cons slice (>MINUS 1,>r,slice>), ->;
  105. cons slice (>MINUS 1,>r, slice >): 
  106.     where (>VSlice*r*zero*upb,slice>), 
  107.     where (>INUM*"0", zero>),
  108.     where (>INUM*MINUS 1, upb>).
  109.